﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ClassicPassWd
{
    /// <summary>
    /// Interaction logic for ReplaceDecode.xaml
    /// </summary>
    public partial class CaesarPasswordDecode : UserControl
    {
        private char[] alphaCharsUpper =
        {
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
            'V', 'W', 'X', 'Y', 'Z'
        };

        public CaesarPasswordDecode()
        {
            InitializeComponent();
        }


        private void GetPassword()
        {
            if (ListViewPassword.Items.Count != 0)
            {
                ListViewPassword.Items.Clear();
            }
            string str1 = BoxProclaim.Text.Replace(" ", "");
            char[] temp = str1.ToCharArray();
            char[] str2 = String.Copy(str1).ToCharArray();
            for (int i = 0; i < 26; i++)
            {
                StringBuilder builder = new StringBuilder();

                for (int j = 0; j < str2.Length; j++)
                {
                    builder.Append(alphaCharsUpper[((str1[j] - 65) + i) % 26]);
                }

                ListViewPassword.Items.Add(i+1+" . "+builder.ToString());
            }


        }


        private void BoxProclaim_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            GetPassword();
        }

        private void BoxProclaim_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Back || e.Key == Key.Delete || e.Key == Key.Space)
            {
                e.Handled = false;
                return;
            }
            e.Handled = new Regex("[^A-Za-z]").IsMatch(GetCharFromKey.KeyChars(e.Key).ToString());
        }
    }
    
}